<template>
  <div class="content">
    <el-form
      :model="form"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <div class="content-item">
        <el-descriptions title="信息审核设置"></el-descriptions>
        <el-form-item label="退租审核" prop="oRentingOutState">
          <el-switch
            v-model="form.oRentingOutState"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后租客退租需要审核，旧数据不受影响</div>
        <el-form-item label="换房审核" prop="oExchangeHouseState">
          <el-switch
            v-model="form.oExchangeHouseState"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后租客换房需要审核，旧数据不受影响</div>
        <el-form-item label="转租审核" prop="oSubleaseState">
          <el-switch
            v-model="form.oSubleaseState"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后租客换房需要审核，旧数据不受影响</div>
        <el-form-item label="续租审核" prop="oContinueLeaseState">
          <el-switch
            v-model="form.oContinueLeaseState"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后租客换房需要审核，旧数据不受影响</div>
      </div>
      <div class="content-item">
        <el-descriptions title="工单审核设置"></el-descriptions>
        <el-form-item label="预约看房审核" prop="woLookHouseCreate">
          <el-switch
            v-model="form.woLookHouseCreate"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后，提交的预约看房需要经过平台审核</div>
        <el-form-item label="密码发放审核" prop="woLookHouseReqPwd">
          <el-switch
            v-model="form.woLookHouseReqPwd"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后，申请临时密码需要经过平台审核</div>
        <el-form-item label="完成看房上传图片开关" prop="woLookHouseUploadImage" label-width="160px">
          <el-switch
            v-model="form.woLookHouseUploadImage"
            active-value="2"
            inactive-value="1"
            @change="changeSwitch"
          ></el-switch>
        </el-form-item>
        <div class="tip-text">开启后，完成看房需要上传图片</div>
      </div>
<!--      <div class="content-item">-->
<!--        <el-descriptions title="智能门锁设置"></el-descriptions>-->
<!--        <el-form-item label="自动冻结开门权限" prop="woLookHouseCreate">-->
<!--          <el-switch-->
<!--            v-model="form.woLookHouseCreate"-->
<!--            active-value="2"-->
<!--            inactive-value="1"-->
<!--            @change="changeSwitch"-->
<!--          ></el-switch>-->
<!--        </el-form-item>-->
<!--        <div class="tip-text">开启后，提交的预约看房需要经过平台审核</div>>-->
<!--      </div>-->

    </el-form>

  </div>
</template>
<script>
import { getSetSwitch, updateSetSwitch } from '@/api/audit/audit'
import { debounce } from '@/utils'
import { mapGetters } from 'vuex'

export default {
  name: 'checkSet',
  data() {
    return {
      form: {
        tenantId: '',
        orderAuditingId: 1,
        signingState: '1', //签约审核状态： 1关闭 2开启
        oRentingOutState: '1', //退租审核状态： 1关闭 2开启
        oExchangeHouseState: '1', //换房审核状态： 1关闭 2开启
        oSubleaseState: '1', //转租审核状态： 1关闭 2开启
        oContinueLeaseState: '1', //续租审核状态： 1关闭 2开启
        timeOutOffState: '1', //订单超时关闭状态：1关闭 2开启
        auditing_STATE_OFF: '1',
        auditing_STATE_ON: '1'
      }
    }
  },
  computed: {
    ...mapGetters(['enterprises'])
  },
  watch: {
    form: {
      handler(newVal, oldVal) {
        console.log(newVal, oldVal)
      },
      deep: true
    }
  },
  created() {
    // this.getSetting()
    this.getSetSwitch()
  },
  methods: {
    // getSetting() {
    //   orderAuditing().then((response) => {
    //     if (response.data) {
    //       this.form = response.data
    //     } else {
    //       this.form['tenantId'] = this.enterprises.tenantId
    //     }
    //   })
    // },
    changeSwitch(val) {
      this.putSetting()
    },
    putSetting: debounce(function() {
      updateSetSwitch(this.form).then((response) => {
        this.$message.success('保存成功')
      })
    }, 500),
    // 获取设置开关
    getSetSwitch() {
      getSetSwitch().then((response) => {
        if (response.data) {
          this.form = response.data
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.content {
  padding: 20px 30px;
}

.tip-text {
  margin-left: 30px;
  font-size: 14px;
  color: #606266;
  font-weight: 500;
  margin-bottom: 30px;
}

::v-deep .el-form-item {
  margin-bottom: 10px;
}
</style>
